package com.example.experiment1;

import android.os.Bundle;
import android.widget.GridLayout;
import android.widget.ToggleButton;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final int ROW_COUNT = 4;
    private static final int COLUMN_COUNT = 4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //1.查找游戏区域布局
        GridLayout gridLayout = findViewById(R.id.gv_game_board);
        gridLayout.setRowCount(ROW_COUNT);
        gridLayout.setColumnCount(COLUMN_COUNT);

        Fruit[][] fruits = new GameAlgorithm().initialGameInterface(ROW_COUNT, COLUMN_COUNT);
        for (int i = 0; i < fruits.length; i++) {
            for (int j = 0; j < fruits[i].length; j++) {
                //2.创建水果图片控件
                ToggleButton tb = new ToggleButton(this);
                tb.setText("");
                tb.setTextOn("");
                tb.setTextOff("");
                tb.setBackgroundResource(fruits[i][j].getImageId());

                //3.往游戏区域中添加控件
                gridLayout.addView(tb, 240, 240);
            }
        }
    }
}